<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8"
        <title>2.3.2对象的解构赋值</title>
    </head>
    <body>
        <script>
            //【例2.19】对象的解构赋值
            //用法 1
            let {age,name}={name:'jack',age:20};
            console.log(name,age);

            //用法 2
            let width =600;
            let height =800;
            let depth;
            console.log(width,height);

            let size = {
                width:200,
                height:300,
            };
            //代码块语句不允许出现在赋值语句左侧,需加小括号变成表达式
            ({width,height}=size);
            console.log(width,height);

            //对象中不存在与变量同名的属性
            ({width,height,depth}=size);
            console.log(width,height,depth);
            //给解构的变量设置默认值
            ({width,height,depth=400}=size);
            console.log(width,height,depth);
            //对象属性赋值给不同名变量
            let personName,name2,age2;
            ({name2:personName,age2}={name2:"tom",age2:20});
            console.log(personName,name2,age2);
        </script>
    </body>
</html>